<?
include "connectDB.php";

$category = 'Mathematics';
while(1){
$query = "select cl_to, page_namespace, page_title from categorylinks join page on page_id = cl_from where cl_to = '$category' and page_namespace = 14";
$result=mysql_query($query);

while($val = mysql_fetch_array($result)){
$concept = $val['page_title'];
$parent = $val['cl_to'];
//echo $val['page_title'].'<br>';

$query2 = "insert into maths_relations(concept,relation,parent) values('$concept',1,'$parent')";
$result1 = mysql_query($query2)or print(mysql_error());
}

$query4 = "update maths_relations set visited = 1 where concept = '$category'" ;
//echo '<br>'.$query4;
$result4 = mysql_query($query4)or print(mysql_error());

$query3 = "select * from maths_relations where visited = 0 limit 1";
$result3 = mysql_query($query3)or print(mysql_error());
$val3 = mysql_fetch_array($result3);
$category = $val3['concept'];


}
?>